facet_grid())
Two highly functional packages:
cowplot (classic)patchwork (newer)set.seed(4534875)
labeler <- function(x) {
annotation_custom(textGrob(x, gp = gpar(fontsize = 30)),
xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
}
M <- tibble(x = rpois(50, 5),
n = 1:50)
p1 <- ggplot(M, aes(x)) +
geom_histogram(bins = 30, fill = "orange") +
scale_x_continuous(breaks = seq(0, 10, by = 2.5),
labels = seq(0, 1000, by = 250)) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
labeler("Plot 1")
p2 <- ggplot(M, aes(x)) +
geom_density() +
labeler("Plot 2")
p3 <- ggplot(M, aes(x = n, y = x)) +
geom_path(color = "darkgreen") +
scale_y_continuous(breaks = seq(0, 10, by = 2.5),
labels = seq(0, 1000, by = 250)) +
labeler("Plot 3")
p4 <- ggplot(M, aes(x = x, y = n)) +
geom_path(color = "purple") +
labeler("Plot 4")plot_grid()plot_grid()+, |, /, and ( ) for arrangement
+ and | work similarly in most casesplot_grid() by nesting two calls to plot_grid()plot_annotation() adds annotation elements to the patchwork& theme() can globally change many plot elements